package com.spring.shops.model.result;

import com.spring.shops.model.entity.TzCategory;
import com.spring.shops.model.vo.CategoryVo;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;


@Data
public class CategoryResult {
    private String code="00000";
    private String msg=null;
    private Object data;
    private String version="mall4j.v230424";
    private Integer timestamp=null;
    private String sign=null;
    private boolean success=true;
    private boolean fail=true;


    public static CategoryResult tableSuccess(TzCategory[] tzCategories) {
        CategoryResult categoryResult = new CategoryResult();
        List<CategoryVo> list=new ArrayList<>();
        for(TzCategory z:tzCategories) {
            CategoryVo categoryVo = new CategoryVo();
            categoryVo.setParentId(z.getParentId());
            categoryVo.setPic(z.getPic());
            categoryVo.setSeq(z.getSeq());
            categoryVo.setStatus(z.getStatus());
            categoryVo.setCategoryId(z.getCategoryId());
            categoryVo.setCategoryName(z.getCategoryName());
            list.add(categoryVo);
        }
        categoryResult.setData(list);
        categoryResult.setFail(false);
        return categoryResult;
    }

    public static CategoryResult saveSuccess(){
        CategoryResult categoryResult = new CategoryResult();
        return categoryResult;
    }
    public static CategoryResult saveFail(){
        CategoryResult categoryResult = new CategoryResult();
        return categoryResult;
    }

    public static CategoryResult deleteSuccess(){
        CategoryResult categoryResult = new CategoryResult();
        categoryResult.setMsg("ok");
        categoryResult.setFail(false);
        return categoryResult;
    }
    public static CategoryResult deleteFail(){
        CategoryResult categoryResult = new CategoryResult();
        categoryResult.setFail(true);
        categoryResult.setSuccess(false);
        categoryResult.setCode("A00001");
        categoryResult.setMsg("请删除子分类，再删除该分类");
        return categoryResult;
    }

    public static CategoryResult infoSuccess(TzCategory z){
        CategoryResult categoryResult = new CategoryResult();
        CategoryVo categoryVo = new CategoryVo();
        categoryVo.setParentId(z.getParentId());
        categoryVo.setPic(z.getPic());
        categoryVo.setSeq(z.getSeq());
        categoryVo.setStatus(z.getStatus());
        categoryVo.setCategoryId(z.getCategoryId());
        categoryVo.setCategoryName(z.getCategoryName());
        categoryVo.setGrade(z.getGrade());
        categoryVo.setRecTime(z.getRecTime());
        categoryVo.setUpdateTime(z.getUpdateTime());
        categoryResult.setData(categoryVo);
        categoryResult.setFail(false);
        return categoryResult;
    }

    public static CategoryResult updateSuccess(){
        CategoryResult categoryResult = new CategoryResult();
        categoryResult.setMsg("ok");
        categoryResult.setFail(false);
        return categoryResult;

    }
    public static CategoryResult updateFail(){
        CategoryResult categoryResult = new CategoryResult();
        categoryResult.setSuccess(false);
        return categoryResult;
    }
}
